package com.atguigu.rabbitmqtest.four;

import com.atguigu.rabbitmqtest.utils.RabbitMqUtils;
import com.rabbitmq.client.*;

public class Consumer {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare("myexchange","fanout");

        String queueName = channel.queueDeclare().getQueue();
        channel.queueBind(queueName,"myexchange","");
        System.out.println("等待接收消息....");
        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), "UTF-8");
            System.out.println("控制台打印接收到的消息"+message);
        };
        channel.basicConsume(queueName, true, deliverCallback, consumerTag -> { });

    }
}
